<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@	taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:url var="baseURI" value="/" />
<!-- 到注册页 -->
<c:url var="register" value="/index.do"/>
<!-- 到系统后台主页 -->
<c:url var="adminIndex" value="/login/adminIndex.do"/>
<!-- 到系统考试主页 -->
<c:url var="studentIndex" value="/login/studentIndex.do"/>
<!-- 登录请求 -->
<c:url var="signUp" value="/login/signUp.do"/>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>登录页</title>
	<!-- 引入外部CSS -->
	<link rel="stylesheet" type="text/css" href="${baseURI}resources/easyui/themes/metro-green/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${baseURI}resources/easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="${baseURI}resources/css/system.css" />
	<!-- 引入外部JS -->
	<script type="text/javascript" src="${baseURI}resources/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="${baseURI}resources/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${baseURI}resources/js/common.js"></script>
	<script type="text/javascript" src="${baseURI}resources/js/myeasyui.js"></script>
	<script type="text/javascript">
		/**登录*/
		function login(){
			$('#login_form').form('submit',{
				url : '${signUp}',
				onSubmit : function(){
					var account = $('#account').textbox('getValue');
					var password = $('#password').textbox('getValue');
					if(account == ''){
						$.messager.alert('提示', "请输入账号！");
						return false;
					}
					if(password == ''){
						$.messager.alert('提示', "请输入密码！");
						return false;
					}
					return true;
				},
				success : function(data){
					var $data = $.parseJSON(data);
					// 登录成功，跳转到首页
					if($data.success){
						if($data.data=='admin'){
							self.location.href='${adminIndex}';
						}
						if($data.data=='student'){
							self.location.href='${studentIndex}';
						}
					} else{
						// 尚未注册（用户不存在）
						if($data.data == 0){
							$.messager.confirm('错误', $data.message, function(r){   
							    if (r){   
							    	self.location.href='${register}';
							    }
							});
						}
						// 密码错误
						if($data.data == 1){
							$.messager.alert('错误', $data.message);
						}
						// 已经考试完毕
						if($data.data == 2){
							$.messager.alert('提示', $data.message);
						}
					}
				}
			});
		}
		
		/**注册*/
		function register(){
			self.location.href='${register}';
		}
	</script>
</head>

<body>
<div style="width:400px; margin:0 auto; padding-top: 50px;">
	<div class="easyui-panel" title="登录到系统${adminUser.account}" style="width:100%;padding:30px 70px 20px 70px;">
		<!-- 表单 -->
		<form id="login_form" method="post">
			<div style="margin-bottom:10px">
				<input id="account" name="account" class="easyui-textbox" style="width:100%;height:40px;padding:12px" data-options="prompt:'账号...',iconCls:'icon-man',iconWidth:38">
			</div>
			<div style="margin-bottom:20px">
				<input id="password" name="password" class="easyui-textbox" type="password" style="width:100%;height:40px;padding:12px" data-options="prompt:'密码...',iconCls:'icon-lock',iconWidth:38">
			</div>
		</form>
		<!-- 按钮 -->
		<div>
			<a href="javascript:login();" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="padding:5px 0px;width:35%;">
				<span style="font-size:14px;">登录</span>
			</a>
			<span style="font-size: 13px;margin-left: 4%">
				没有账号？请先<a href="javascript:register();">注册</a>
			</span>
		</div>
	</div>
</div>
</body>
